package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.dao.QuarantineCenterHarmlessDao;
import com.jiantong.work.impl.manager.QuarantineCenterHarmlessManager;
import com.jiantong.work.model.QuarantineCenterHarmless;
import com.jiantong.work.service.QuarantineCenterHarmlessWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by niufei on 2017/3/30.
 *
 */
@Slf4j
@Service
@RpcProvider
public class QuarantineCenterHarmlessWriteServiceImpl implements QuarantineCenterHarmlessWriteService{

    private final QuarantineCenterHarmlessManager quarantineCenterHarmlessManager;
    private final QuarantineCenterHarmlessDao quarantineCenterHarmlessManagerDao;

    @Autowired
    public QuarantineCenterHarmlessWriteServiceImpl(QuarantineCenterHarmlessManager quarantineCenterHarmlessManager,QuarantineCenterHarmlessDao quarantineCenterHarmlessManagerDao) {
        this.quarantineCenterHarmlessManager = quarantineCenterHarmlessManager;
        this.quarantineCenterHarmlessManagerDao=quarantineCenterHarmlessManagerDao;
    }

    @Override
    public Response<Map<String, Object>> createQuarantineCenterHarmless(QuarantineCenterHarmless quarantineCenterHarmless, Integer toStatus) {
        try{
            return Response.ok(quarantineCenterHarmlessManager.createQuarantineCenterHarmless(quarantineCenterHarmless,toStatus));
        }catch (Exception e){
            log.error("failed to create quarantineCenterHarmless error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("quarantineCenterHarmless.create.failed");
        }
    }

    @Override
    public Response<Map<String, Object>> updateQuarantineCenterHarmless(QuarantineCenterHarmless quarantineCenterHarmless, Integer toStatus) {
        try{
            return Response.ok(quarantineCenterHarmlessManager.updateQuarantineCenterHarmless(quarantineCenterHarmless,toStatus));
        }catch (Exception e){
            log.error("failed to update quarantineCenterHarmless error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("quarantineCenterHarmless.update.failed");
        }
    }

    @Override
    public Boolean update(QuarantineCenterHarmless quarantineCenterHarmless) {
        return quarantineCenterHarmlessManagerDao.update(quarantineCenterHarmless);
    }
}
